package com.xtravel.common.helper;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class EncryptHelper {

	public static String getMd5String(String value)
			throws NoSuchAlgorithmException {
		MessageDigest md5 = MessageDigest.getInstance("MD5");
		md5.update(value.getBytes());
		byte[] m = md5.digest(); // 加密
		return getString(m);
	}

	public static String getString(byte[] value) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < value.length; i++) {
			sb.append(value[i]);
		}

		return sb.toString();
	}

	public static String encryptDES(String encryptString)
			throws Exception {
		return DESHelper.getInstance().encode(encryptString);
	}

	public static String decryptDES(String decryptString)
			throws Exception {
		return DESHelper.getInstance().decode(decryptString);
	}
}
